#ifndef CONFIG_HPP
#define CONFIG_HPP

namespace Config_n
{
/* region ==============================  预编译  ==============================*/
#define IS_DEBUG_MODE     0x01u // 是否是debug模式，0为否，1为是，开启debug模式后，常规任务将被关闭，开启debug任务，一些debug变量也被赋予内存，方便ozone查看
#define IS_GIMBAL_USE_PID 0x00u // 云台是否采用PID调控方式，0为lqr调控，1为pid调控
#define IS_DEBUG_MODE_FRICTION    0x00u
#define IS_DEBUG_MODE_GIMBAL      0x01u
// endregion

/* region ============================== 发射配置 ==============================*/
// 摩擦轮
#define FRICTION_MOTOR_NUMS   0x03u   // 摩擦轮电机数量
#define FRICTION_WHEEL_RADIUS 0.06f   // 轮半径，单位m

// 下摩擦轮
#define FRICTION_WHEEL_DOWN_PID_KP    8.0f
#define FRICTION_WHEEL_DOWN_PID_KI    0.01f
#define FRICTION_WHEEL_DOWN_PID_KD    5.0f
#define FRICTION_WHEEL_DOWN_PID_I_MAX 4000.0f
#define FRICTION_WHEEL_DOWN_ID        0x03u
#define FRICTION_WHEEL_DOWN_USE_CAN   &hcan2

// 左摩擦轮
#define FRICTION_WHEEL_L_PID_KP    8.0f
#define FRICTION_WHEEL_L_PID_KI    0.01f
#define FRICTION_WHEEL_L_PID_KD    5.0f
#define FRICTION_WHEEL_L_PID_I_MAX 10000.0f
#define FRICTION_WHEEL_L_ID        0x02u
#define FRICTION_WHEEL_L_USE_CAN   &hcan2

// 右摩擦轮
#define FRICTION_WHEEL_R_PID_KP    8.0f
#define FRICTION_WHEEL_R_PID_KI    0.01f
#define FRICTION_WHEEL_R_PID_KD    5.0f
#define FRICTION_WHEEL_R_PID_I_MAX 9000.0f
#define FRICTION_WHEEL_R_ID        0x01u
#define FRICTION_WHEEL_R_USE_CAN   &hcan1

// 拨弹盘
#define RELOADER_MOTOR_PID_A_KP    0.15f
#define RELOADER_MOTOR_PID_A_KI    0.0f
#define RELOADER_MOTOR_PID_A_KD    0.67f
#define RELOADER_MOTOR_PID_S_KP    10.0f
#define RELOADER_MOTOR_PID_S_KI    0.0f
#define RELOADER_MOTOR_PID_S_KD    2.0f
#define RELOADER_MOTOR_ID          0x04u

// 弹速与弹频
#define MAX_SHOOT_FREQ  8.0f    // 最大弹频，单位Hz
#define MIN_SHOOT_FREQ  .99f    // 最小弹频，单位Hz
#define MAX_SHOOT_SPEED 6000.0f // 最大摩擦轮转速，单位rpm
#define MIN_SHOOT_SPEED 3000.0f // 最小摩擦轮转速，单位rpm
#define SPEED_SENSOR_RC 1.0f    // DR16加减弹速灵敏度
#define FREQ_SENSOR_RC  .001f   // DR16加减弹频灵敏度
#define SPEED_SENSOR_TC 1.0f
#define FREQ_SENSOR_TC  .001f

// 特别参数
#define FIRE_DISABLE_TIME          .5f   // 失能处理时间
#define FIRE_ONE_SHOT_TIME         .3f   // 单发时间
#define FIRE_STUCK_TIME            .22f  // 卡弹回退时间
#define RELOADER_GEAR_RATIO        36    // 减速比
#define RELOADER_ROUND_BULLETS     8     // 拨弹盘每圈弹数量
#define RELOADER_ENCODER_TO_SHOOT1 (8192 * RELOADER_GEAR_RATIO / RELOADER_ROUND_BULLETS) // 打一发编码器转动值
// endregion

/* region ============================== 云台配置 ==============================*/
// yaw GM6020
#define YAW_MOTOR_PID_A_KP 6.0f
#define YAW_MOTOR_PID_A_KI .0f
#define YAW_MOTOR_PID_A_KD .2f
#define YAW_MOTOR_PID_S_KP 3.0f
#define YAW_MOTOR_PID_S_KI .0f
#define YAW_MOTOR_PID_S_KD .3f
#define YAW_MOTOR_PID_I_KI -0.0006f // 0.02
#define YAW_MOTOR_LQR_1    10.0f    //{6, 0.175};  // 0.23}
#define YAW_MOTOR_LQR_2    .198f
#define YAW_MOTOR_SPEED_MAX_OUT 300
#define YAW_ECD_MAX             0
#define YAW_ECD_MIN             -3000

#define YAW_MOTOR_USE_CAN       &hcan1
#define YAW_MOTOR_ID            0x02u

// pitch DM电机
#define PITCH_MOTOR_PID_A_KP 7.5f // 8.5f
#define PITCH_MOTOR_PID_A_KI .0f
#define PITCH_MOTOR_PID_A_KD 1.0f // 1.7f
#define PITCH_MOTOR_PID_I_KI .0023f // 0.0031 // 0.0031   //0.00183,//0.00075, // 0.00075, // 0.0085, // 0.02
#define PITCH_MOTOR_V        0.1f
#define PITCH_MOTOR_T        0.0f
#define PITCH_MOTOR_LQR_1    41.5f       // {32.0, -0.59}; // +,-
#define PITCH_MOTOR_LQR_2    -0.77f      // 速度kp-0.00372 0.01572
#define PITCH_POS_MAX        .24   //8度
#define PITCH_POS_MIN        -0.59 //

#define PITCH_MOTOR_USE_CAN  &hcan1
#define PITCH_MOTOR_TX_ID    0x01u
#define PITCH_MOTOR_RX_ID    0x11u

// IMU BMI088

// 云台灵敏度
#define YAW_SENSOR_RC   .0004f // 0.0006
#define PITCH_SENSOR_RC .00042f// 0.00022f //发送给大妙为
#define YAW_SENSOR_TC   .001f
#define PITCH_SENSOR_TC .001f

// 重力补偿力矩 = 云台pitch连杆力臂---mgl* cos(thita)
#define LEVER_ARM_OF_PITCH      0.0885  //0.37131808 // mgl = 88.5mm *0.595kg*9.8
#define LEVER_ARM_TO_PITCH_COF  4.77    //4.7度
#define GIMBAL_MG               16      // 13.5; // 14.73;

// 特殊参数
#define RAD_TO_ANGLE             57.29f // 弧度转角度的系数
#define GIMBAL_DISABLE_TIME      0.5f   // 失能处理时间
#define GIMBAL_CHANGE_STATE_TIME 2.0f   // 摇杆切换状态时间
#define GIMBAL_ANGLE_TO_ENCODER  22.7f  // 大疆电机角度转编码器值

// endregion
}

#endif //CONFIG_HPP
